<template>
  <div class="center-container">
    <div class="self-info">
      <div class="title">员工信息</div>
      <div class="info-main flex-box">
        <div>
          <div><i class="el-icon-office-building"></i>公司 {{info.businessName}}</div>
          <div><i class="el-icon-files"></i>部门 {{info.departmentName}} {{info.groupName}}</div>
          <div><i class="el-icon-user"></i>职位 {{info.jd}}</div>
        </div>
        <div>
<!--          <div>已加入企业 {{info.days}} 天</div>-->
<!--          <div>已累计学习 {{info.hours}} 小时</div>-->
        </div>
      </div>
    </div>
    <div class="on-learn">
      <div class="title">正在学习</div>
      <div class="course-list">
        <div class="course-item flex-box" v-for="course in courses" :key="course.id">
          <div class="cover img-box">
            <img :src="course.cover" alt="cover">
          </div>
          <div class="info flex-box">
            <div>
              <div class="course-name">{{course.name}}</div>
              <div class="status">共{{course.sectionNum}}节 | 已学{{course.sectionLearnedNum}}节 学完{{(course.sectionLearnedNum/course.sectionNum).toFixed(2)*100 + '%' | percent}}</div>
            </div>
            <div class="last-learn flex-box">
              <div>上次学到：<span>{{course.lastSectionContentName}}</span></div>
              <div @click="toStudy(course.id)" class="primary-btn">前往学习</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "EESelfCenterView",
  data() {
    return {
      info: {},
      courses: []
    }
  },
  mounted() {
    this.getBusinessInfo()
  },
  methods:{
    getBusinessInfo(){
      this.$api
          .getBusinessInfo().then(({data})=>{
            if (data.data){
              this.info = data.data
              this.getUserCourseList()
            }else{
              alert("您还未加入任何企业！请联系企业管理员！")
            }
      })
    },
    getUserCourseList(){
      this.$api.getUserCourseList({
        pageSize: 20,
        pageNow:1 ,
        status: 4,
        type: 1,
        process: 2
      }).then(({data}) => {
        console.log("res",data)
        this.courses = data.data.rows;
        this.loading = false;
      });
    },
    toStudy(courseId){
      this.$router.push({
        name: "learn-notice",
        params: { courseId: courseId },
      });
    }
  }
}
</script>

<style scoped lang="scss">
.center-container {
  min-height: 600px;
}
.title {
  margin-bottom: 20px;
}
.self-info {
  margin-bottom: 20px;
  border-bottom: 1px solid #e5ecef;
  .info-main {
    justify-content: space-between;
    padding: 0 100px 20px 10px;
    > div >div {
      font-size: 14px;
      margin: 5px 0;
    }
  }
}
.course-item {
  padding: 10px;
  .cover {
    width: 150px;
    height: auto;
    margin-bottom: 0;
    margin-right: 10px;
  }
  .info{
    flex: 1;
    flex-direction: column;
    justify-content: space-between;
  }
  .course-name {
    font-size: 18px !important;
    margin-bottom: 5px;
  }
  .course-teacher > span{
    font-size: 14px;
    margin-right: 5px;
  }
  .last-learn {
    font-size: 14px;
    justify-content: space-between;
    align-items: flex-end;
    span {
      cursor: pointer;
      color: #8EB9FF;
      transition: .3s;
      &:hover {
        transition: .3s;
        color: #2c6fdf;
      }
    }
  }
}
</style>
